home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-09 | 8.9 KB | 195 lines | [TEXT/R*ch] |
- syslog(3C) syslog(3C)
-
- NAME
- syslog(), openlog(), closelog(), setlogmask() - control system log
-
- SYNOPSIS
- #include <syslog.h>
-
- int syslog(int priority, const char *message, int parameters, ...);
-
- int openlog(const char *ident, int logopt, int facility);
-
- int closelog(void);
-
- int setlogmask(int maskpri);
-
- DESCRIPTION
- syslog() writes a message onto the system log maintained by
- syslogd (see syslogd(1M)). The message is tagged with
- priority. The message is similar to a printf(3S)
- format string except that %m is replaced by the error
- message associated with the current value of errno. A
- trailing newline is added if needed.
-
- This message is read by syslogd and written to the
- system console, log files, selected users' terminals,
- or forwarded to syslogd on another host as appropriate.
-
- priority is encoded as the logical OR of a level and a
- facility. The level signifies the urgency of the
- message, and facility signifies the subsystem
- generating the message. facility can be encoded
- explicitly in priority, or a default facility can be
- set with openlog() (see below).
-
- level is selected from an ordered list:
-
- LOG_EMERG A panic condition. This is
- normally broadcast to all
- users.
-
- LOG_ALERT A condition that should be
- corrected immediately, such as
- a corrupted system database.
-
- LOG_CRIT Critical conditions, such as
- hard device errors.
-
- LOG_ERR Errors.
-
- LOG_WARNING Warning messages.
-
- LOG_NOTICE Conditions that are not error
- conditions, but should
- possibly be handled specially.
-
- LOG_INFO Informational messages.
-
- LOG_DEBUG Messages that contain
- information normally of use
- only when debugging a program.
-
- syslog() does not log a message that does not have a
- level set.
-
- If syslog() cannot pass the message to syslogd, it
- attempts to write the message on /dev/console if the
- LOG_CONS option is set (see below).
-
- openlog() can be called to initialize the log file, if special
- processing is needed. ident is a string that precedes
- every message. logopt is a mask of bits, logically
- OR'ed together, indicating logging options. The values
- for logopt are:
-
- LOG_PID Log the process ID with each
- message; useful for
- identifying instantiations of
- daemons.
-
- LOG_CONS Force writing messages to the
- console if unable to send it
- to syslogd. This option is
- safe to use in daemon
- processes that have no
- controlling terminal because
- syslog() forks before opening
- the console.
-
- LOG_NDELAY Open the connection to syslogd
- immediately. Normally, the
- open is delayed until the
- first message is logged. This
- is useful for programs that
- need to manage the order in
- which file descriptors are
- allocated.
-
- LOG_NOWAIT Do not wait for children
- forked to log messages on the
- console. This option should
- be used by processes that
- enable notification of child
- termination via SIGCLD,
- because syslog() might
- otherwise block, waiting for a
- child whose exit status has
- already been collected.
-
- facility encodes a default facility to be assigned to
- all messages written subsequently by syslog() with no
- explicit facility encoded.
-
-
-
- LOG_KERN Messages generated by the
- kernel. These cannot be
- generated by any user
- processes.
-
- LOG_USER Messages generated by random
- user processes. This is the
- default facility identifier if
- none is specified.
-
- LOG_MAIL The mail system.
-
- LOG_DAEMON System daemons, such as
- inetd(1M), ftpd(1M), etc.
-
- LOG_AUTH The authorization system:
- login(1), su(1), getty(1M),
- etc.
-
- LOG_LPR The line printer spooling
- system: lp(1), lpsched(1M),
- etc.
-
- LOG_LOCAL0 Reserved for local use.
- Similarly for LOG_LOCAL1
- through LOG_LOCAL7.
-
- closelog() closes the log file.
-
- setlogmask() sets the log priority mask to maskpri and returns the
- previous mask. Calls to syslog() with a priority not
- set in maskpri are rejected. The mask for an
- individual priority pri is calculated by the macro
- LOG_MASK(pri); the mask for all priorities up to and
- including toppri is given by the macro
- LOG_UPTO(toppri). By default, all priorities are
- logged.
-
- RETURN VALUE
- syslog() returns zero if it is successful in writing to the system log
- or if priority is masked out. It returns -1 if it is unable to write
- to the system log or if priority is out of range.
-
- EXAMPLES
- who logs a message regarding some sort of unexpected and serious
- error:
-
- syslog(LOG_ALERT, "who: internal error 23");
-
- ftpd uses openlog() to arrange to log its process ID, to log to the
- console if necessary, and to log in the name of the daemon facility:
-
- openlog("ftpd", LOG_PID|LOG_CONS, LOG_DAEMON);
-
- Arrange to log messages only at levels LOG_ERR and lower:
-
- setlogmask(LOG_UPTO(LOG_ERR));
-
- Typical usage of syslog() to log a connection:
-
- syslog(LOG_INFO, "Connection from host %d", CallingHost);
-
- If the facility has not been set with openlog(), it defaults to
- LOG_USER.
-
- Explicitly set the facility for this message:
-
- syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
-
- WARNINGS
- A call to syslog() has no effect unless the syslog daemon
- (syslogd(1M)) is running. openlog() does not copy and store the ident
- string internally; it stores only a character pointer. Therefore it
- is the responsibility of the programmer to make sure that the ident
- argument points to the correct string until the log file is closed.
-
- AUTHOR
- syslog() was developed by the University of California, Berkeley.
-
-